<?php
session_start();
require_once(ABSPATH . 'wp-admin/includes/user.php');
require_once(ABSPATH . WPINC . '/registration.php');
require_once dirname( __FILE__ ) . '/form-process.php'; 
?>
<?php get_header(); ?>
<!-- TextboxList is not priceless for commercial use. See <http://devthought.com/projects/mootools/textboxlist/> -->		
<!-- required stylesheet for TextboxList -->
<link rel="stylesheet" href="<?php echo bloginfo('url') . "/wp-content/themes/" . FOLDER_STR; ?>/js/TextboxList.css" type="text/css" media="screen" charset="utf-8" />
<!-- required stylesheet for TextboxList.Autocomplete -->
<link rel="stylesheet" href="<?php echo bloginfo('url') . "/wp-content/themes/" . FOLDER_STR; ?>/js/TextboxList.Autocomplete.css" type="text/css" media="screen" charset="utf-8" />

<script src="<?php echo bloginfo('url') . "/wp-content/themes/" . FOLDER_STR; ?>/js/mootools-1.2.1-core-yc.js" type="text/javascript" charset="utf-8"></script>		

<!-- required for TextboxList -->
<script src="<?php echo bloginfo('url') . "/wp-content/themes/" . FOLDER_STR; ?>/js/GrowingInput.js" type="text/javascript" charset="utf-8"></script>
        
<script src="<?php echo bloginfo('url') . "/wp-content/themes/" . FOLDER_STR; ?>/js/TextboxList.js" type="text/javascript" charset="utf-8"></script>		
<script src="<?php echo bloginfo('url') . "/wp-content/themes/" . FOLDER_STR; ?>/js/TextboxList.Autocomplete.js" type="text/javascript" charset="utf-8"></script>
<!-- required for TextboxList.Autocomplete if method set to 'binary' -->
<script src="<?php echo bloginfo('url') . "/wp-content/themes/" . FOLDER_STR; ?>/js/TextboxList.Autocomplete.Binary.js" type="text/javascript" charset="utf-8"></script>		

<!-- sample initialization -->
<script type="text/javascript">
//Function explode use Javascript
function explode (delimiter, string, limit) {    
	 var emptyArray = { 0: '' };
	
	// third argument is not required
	if ( arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined' ) {
		return null;
	}
	
	if ( delimiter === '' || delimiter === false || delimiter === null ) {
		return false;
	}
	if ( typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object' ) 
	{
		return emptyArray;    
	} 
    if ( delimiter === true ) {
        delimiter = '1';
    }    
    if (!limit) 
	{
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;    
	}
}
//Kiem tra user khi nhan ","
function alpha(e) { 	
	var unicode = e.charCode ? e.charCode : e.keyCode;	
	if(unicode==44)
	{		
		var val = document.getElementById('form_tags_input_3').value;
		var get_val = explode(",",val);	
		for(var i=0;i<get_val.length;i++)
		{
			check(get_val[i]);			   
		}	
	}		
} 
//Ajax kiem tra invite users nhap vao
function check(str)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var res = xmlhttp.responseText;
			if(res == 0)
			{
				alert('User '+str+' is not correct !');	
			}
		}
	}
	var queryString = "?invite=" + str;		
	xmlhttp.open("GET", "<?php echo bloginfo('url') . "/wp-content/themes/" . FOLDER_STR . "/ajax_check_users.php"?>" + queryString, true);
	xmlhttp.send(); 
}
</script>
<script type="text/javascript" charset="utf-8">	
window.addEvent('load', function(){								 
	// Standard initialization
	var t = new TextboxList('form_tags_input', {  });
	t.add('Football').add('Sport').add('Tag 3');	
   	
	// With custom adding keys 
	var t2 = new TextboxList('form_tags_input_2', {bitsOptions:{editable:{addKeys: 188}}});	
	t2.add('');
	
	// With custom adding keys 
	var t2 = new TextboxList('form_tags_input_3', {bitsOptions:{editable:{addKeys: 188}}});
	t2.add('');

	
});
</script>

<!-- sample style -->
<style type="text/css" media="screen">
    .form_tags { margin-bottom: 10px; }
    
    /* Setting widget width example */
    .textboxlist { width: 400px; }
    
    /* Preloader for autocomplete */
    .textboxlist-loading { background: url('<?php echo bloginfo('url') . "/wp-content/themes/" . FOLDER_STR; ?>/images/spinner.gif') no-repeat 380px center; }
    
    /* Autocomplete results styling */
    .form_friends .textboxlist-autocomplete-result { overflow: hidden; zoom: 1; }
    .form_friends .textboxlist-autocomplete-result img { float: left; padding-right: 10px; }
    
    .note { color: #666; font-size: 90%; }
    #footer { margin: 50px; text-align: center; }
</style>

<div id="content">
	<div class="left">
    	<h2>Ask a question</h2>
        
        <div class="info">
        	<p>Try to be as detailed as possible in formuling your question and describing it. <br />Choosing tags carefully will also help you in getting the right answers as soon as posible.</p>                        
        </div>
        
        <div class="question-form"> 
        <form action="" method="post" id="new_post" name="new_post" enctype="multipart/form-data">
        <input type="hidden" name="action" value="post" />
        <?php wp_nonce_field('new-post'); ?>
                    <p>Your Question:</p>
                    <?php
					if($error!="")
						echo "<p>$error</p>";
					?>
                    <div class="text-publish">
                      <textarea name="question" cols='75' rows='3' value="" ></textarea>
                    </div>
                    <p>Describe your question:</p>
                    <div class="text-publish">
                      <textarea name="content" cols='75' rows='6' value="" ></textarea>
                    </div>
					<?php 
					//get all categories
                    $query = "SELECT  t.term_id,t.name
			 					FROM    wp_terms t JOIN wp_term_taxonomy tt ON t.term_id=tt.term_id
			 					WHERE tt.taxonomy = 'category' AND t.term_id >1  ";                  
                    $cate = $wpdb -> get_results($query);					
                    ?>
                    
                    
                
    <div style="display:none;" class="form_tags"><input type="text" name="test" value="" id="form_tags_input" /></div>
    			<select id="cate" name="cate" style="float:right;">
                <option value="0">Chose the Category...</option>
                <?php
                foreach ($cate as $c)
                {
                ?>
                    <option value="<?php echo $c->term_id; ?>"><?php echo $c->name; ?></option>
                <?php
                }
                ?>
            	</select>     
    
                <p style="float:right; margin-right:10px;">Add new category </p>
                
                <p>Tags: <font class="comma">Separated by comma</font></p>
                <div class="form_tags"><input type="text" name="tags" value="" id="form_tags_input_2" /></div>
                <div class="height"></div>
                <p>Invite Users: <font class="comma">Separated by comma</font></p>
                <div class="form_tags" onkeypress="return alpha(event);" ><input type="text" name="users"  value="" id="form_tags_input_3" /></div>
                
                <div class="submit">
                    <div class="publish-submit">
                        <input type="image" onclick="submit()" src="<?php echo get_bloginfo('template_directory'); ?>/images/publish-submit.jpg" name="submitform" />
                    </div>
                    <div class="terms">
                        <p>By submiting this question you agree with our <a href="#">Terms of Service</a>.</p>
                    </div>
                </div>		
                
        </form>
        </div>
    </div> <!--//Left-->
    <?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>

